package com.loukou.lkt.company.dao;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;

import com.loukou.lkt.company.entity.User;


public interface UserDao extends PagingAndSortingRepository<User, Integer>, JpaSpecificationExecutor<User> {

	User findByUsernameAndPassword(String username, String pwd);
	
	List<User> findByUsernameLike(String username);
	
	List<User> findByIdIn(List<Integer> ids);

	Page<User> findByIdIn(List<Integer> userIds, Pageable pageable);

	Page<User> findByRealName(String realname, Pageable pageable);

	Page<User> findByRealNameAndIdIn(String realname, List<Integer> userIds, Pageable pageable);
	
	@Modifying
	@Transactional
	@Query("update User set realName = ?1 , username = ?2 where id = ?3")
	void updateUser(String realname, String username, int userId);

	User findByUsername(String username);

	User findByUsernameAndIdNot(String username, int userId);	
}
